{extend name="public/base"}

{block name="title"}就行天下-店铺信息{/block}

{block name="style"}
<link rel="stylesheet" href="__STATIC__/home/css/index.css" />
{/block}

{block name="main"}
<div class="pageControl lookIndent bg-f7">
    <div class="main-top"></div>
    <div class="msui_nav msui_navTop">
        <a class="msui_navTop-back" href="javascript:history.back();"><i class="micon-back"></i></a>
        <h1 class="msui_navTop-title">订单详情</h1>
        <a href="" class="msui_navTop-right msui_navTop-cnav"><i class="micon-cnav"></i></a>
    </div>
    <div>
        <img src="__STATIC__/home/images/flow_2.png" alt="">
    </div>
    <div class="weui-cell">
        <div class="weui-cell__bd">
            <p>配送方式: <span>送货上门</span></p>
            <p class="cl-9999">订单号: <span>{$data.order_sn}</span></p>
        </div>
    </div>
    <div class="">
        <div class="weui-cell">
            <div class="weui-cell__hd indentImg">
                <img src="{$data.headimgurl}" alt="">
            </div>
            <div class="weui-cell__bd">
                <p class="fs07">{$data.nickname}</p>
                <div class="my-flex1 cl-9999 fs065">
                    下单时间: <span>{$data.create_time|date='Y-m-d H:i:s', ###}</span>
                </div>
            </div>
            <div class="weui-cell__ft">
            </div>
        </div>
        {empty name="data.products"}
            <div class="weui-cell confirmOrder">
                <div class="weui-cell__hd">
                    <img src="__STATIC__/home/images/product3.png" alt="">
                </div>
                <div class="weui-cell__bd orderDemand">
                    <p class="fs06 listFont-1">{$data.msg}</p>
                    <p class="fs06">喝酒时间: <span>{$data.drink_time|date="m-d H:i", ###}</span></p>
                </div>
            </div>
        {else /}
            {volist name="data.products" id="v"}
                <div class="weui-cell confirmOrder">
                    <div class="weui-cell__hd">
                        <img src="{$v.image}" alt="">
                    </div>
                    <div class="weui-cell__bd ">
                        <p class="fs06 listFont">{$v.name}</p>
                    </div>
                    <div class="weui-cell__ft fs06">
                        <p>￥<span  class="buyButton_price">{$v.price}</span></p>
                        {eq name="data.status" value="2"}
                        <p class="buyButton mtop01">
                            <button {eq name="v.num" value="1"} disabled="disabled" {/eq} class="subtract" type="button" data-order-product-id="{$v.id}">-</button>
                            <span>{$v.num}</span>
                            <button class="add" type="button" data-order-product-id="{$v.id}">+</button>
                            <button class="delete" type="button" data-order-product-id="{$v.id}" style="color: #fff">X</button>
                        </p>
                        {else /}
                        <p>x{$v.num}</p>
                        {/eq}
                    </div>
                </div>
            {/volist}
        {/empty}
        <div class="weui-cell">
            <div class="weui-cell__bd">

            </div>
            <div class="weui-cell__ft" style="padding-right: 10px">
                <div class="fs065">
                    共<span class="total_count">{$data.products_num}</span>件商品 合计: ￥<span class="total_price">{$data.total_price}</span>
                </div>
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd img_08 mr06">
                <img src="__STATIC__/home/images/address.png" alt="">
            </div>
            <div class="weui-cell__bd">
                <p class="fs06"><span>联系电话 </span> <span>{$data.mobile}</span></p>
                <p class="fs06 cl-9999"><span>{$data.address}</span></p>
            </div>
        </div>
    </div>
    {if condition="$data.status == 2 && $data.type == 1"}
    <div class="p05">
        <!--彩色背景class为bg-c40，黑色背景为bg-ae-->
        <a href="{:url('shop_order_add_product', ['order_id' => $data.id, 'id' => $shop_id])}" class="weui-btn bg-c40">添加商品</a>
    </div>
    <!--彩色背景class为indent-btn-bg，黑色背景为indent-btn-999-->
    <a href="javascript:;" class="demand-btn indent-btn-bg push-order" data-order-id="{$data.id}" data-shop-id="{$shop_id}">推送商品</a>
    {/if}
</div>
{/block}

{block name="javascript"}
<script src="__STATIC__/home/js/shop_order.js"></script>
<script>
    $(function () {
        // 减数量
        $('.buyButton button.subtract').click(function () {
            var t=$(this).next().html();
            if(t>2){
                t-=1;
            }else if(t=2){
                t=1;
                $(this).attr('disabled','disabled')
            }
            var _this = $(this);
            $.showLoading();
            $.post('{:url("edit_order_product_num")}', {id: $(this).data('order-product-id'), num : t, shop_id : '{$shop_id}', order_id : '{$data.id}'}, function (msg) {
                if (msg.code == 200) {
                    _this.next().html(t);
                    total();
                } else {
                    $.hideLoading();
                    $.toptip(msg.msg);
                }
            });
        });
        // 加数量
        $('.buyButton button.add').click(function () {
            var t=parseFloat($(this).prev().html());
            t+=1;
            $('.buyButton button.subtract').removeAttr('disabled','disabled')
            var _this = $(this);
            $.showLoading();
            $.post('{:url("edit_order_product_num")}', {id: $(this).data('order-product-id'), num : t, shop_id : '{$shop_id}', order_id : '{$data.id}'}, function (msg) {
                if (msg.code == 200) {
                    _this.prev().html(t);
                    total();
                } else {
                    $.hideLoading();
                    $.toptip(msg.msg);
                }
            });
        });

        // 删除商品
        $('.buyButton button.delete').click(function () {
            var _this = $(this);
            $.confirm('确认删除？', function () {
                $.showLoading();
                $.post('{:url("delete_order_product")}', {id: _this.data('order-product-id'), shop_id : '{$shop_id}', order_id : '{$data.id}'}, function (msg) {
                    if (msg.code == 200) {
                        _this.parents('.confirmOrder').remove();
                        $.toptip('删除成功', 'success');
                        total();
                    } else {
                        $.hideLoading();
                        $.toptip(msg.msg);
                    }
                });
            });
        });

        // 结算数量，价格
        function total() {
            $.loading_hide();
            var count = 0, price = 0;
            $('.confirmOrder').each(function (i, d) {
                var _this_num = parseInt($(this).find('.buyButton span').html())
                var _this_price = parseFloat($(this).find('.buyButton_price').html()) * _this_num;
                price += _this_price;
                count += _this_num;
            });

            $('.total_count').html(count);
            $(".total_price").html(number_format(roundNumber(price,2)));
        }
    });
</script>
{/block}